from flask_login import LoginManager

login_manager = LoginManager()

from flask import Flask
from apps.web.book import web
from apps.models.book import db
from flask_mail import Mail
mail = Mail()

def create_app():
    app = Flask(__name__)
    app.config.from_object('apps.settings')
    app.config.from_object('apps.secure')
    register_bp(app)

    db.init_app(app)
    login_manager.init_app(app)
    login_manager.login_view = 'web.login'
    login_manager.login_message = '请先登录'
    mail.init_app(app)
    # db.drop_all(app=app)
    db.create_all(app=app)
    return app


def register_bp(app):
    app.register_blueprint(web)
